Option Explicit On 
Option Strict On

Public Class frmTaxonClass
    Inherits System.Windows.Forms.Form
    Public Shared oTaxRank As TaxonClass
    Public Shared bUpdate As Boolean
    Dim sEmpireValue As String = "Biovitae"
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents txtCommon As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtRValue As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents cboxRName As System.Windows.Forms.ComboBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents button_example As System.Windows.Forms.Button
    Dim sEmpireCommon As String = "Carbon-based lifeforms"


#Region " Windows Form Designer generated code "

    Public Sub New(ByVal inTaxa As TaxonClass)
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        oTaxRank = inTaxa
        bUpdate = False

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmTaxonClass))
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.cboxRName = New System.Windows.Forms.ComboBox
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnOK = New System.Windows.Forms.Button
        Me.txtCommon = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.txtRValue = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.button_example = New System.Windows.Forms.Button
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'ToolTip1
        '
        Me.ToolTip1.IsBalloon = True
        Me.ToolTip1.ShowAlways = True
        Me.ToolTip1.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info
        '
        'cboxRName
        '
        Me.cboxRName.Items.AddRange(New Object() {"Empire", "Kingdom", "Division", "Phylum", "Subphylum", "Superclass", "Class", "Subclass", "Infraclass", "Superorder", "Order", "Suborder", "Infraorder", "Superfamily", "Family", "Subfamily", "Tribe", "Subtribe", "Genus", "Species"})
        Me.cboxRName.Location = New System.Drawing.Point(135, 6)
        Me.cboxRName.Name = "cboxRName"
        Me.cboxRName.Size = New System.Drawing.Size(160, 21)
        Me.cboxRName.TabIndex = 23
        Me.ToolTip1.SetToolTip(Me.cboxRName, "Select or type in appropriate rank name")
        '
        'ImageList1
        '
        Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        Me.ImageList1.Images.SetKeyName(0, "")
        '
        'Panel1
        '
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Panel1.Controls.Add(Me.LinkLabel1)
        Me.Panel1.Controls.Add(Me.TextBox1)
        Me.Panel1.Location = New System.Drawing.Point(15, 184)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(450, 37)
        Me.Panel1.TabIndex = 31
        '
        'LinkLabel1
        '
        Me.LinkLabel1.Location = New System.Drawing.Point(231, 8)
        Me.LinkLabel1.Name = "LinkLabel1"
        Me.LinkLabel1.Size = New System.Drawing.Size(216, 23)
        Me.LinkLabel1.TabIndex = 12
        Me.LinkLabel1.TabStop = True
        Me.LinkLabel1.Text = "Integrated Taxonomic Information System"
        '
        'TextBox1
        '
        Me.TextBox1.AcceptsReturn = True
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.TextBox1.Location = New System.Drawing.Point(8, 8)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.ReadOnly = True
        Me.TextBox1.Size = New System.Drawing.Size(232, 13)
        Me.TextBox1.TabIndex = 11
        Me.TextBox1.TabStop = False
        Me.TextBox1.Text = "Most taxonomic descriptions can be found at:"
        '
        'btnCancel
        '
        Me.btnCancel.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnCancel.Image = Global.MetaDoc.My.Resources.Resources.Cancel_16x16
        Me.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnCancel.Location = New System.Drawing.Point(390, 155)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(75, 23)
        Me.btnCancel.TabIndex = 30
        Me.btnCancel.Text = "Cancel"
        Me.btnCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'btnOK
        '
        Me.btnOK.Enabled = False
        Me.btnOK.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnOK.Image = Global.MetaDoc.My.Resources.Resources.Ok_16x16
        Me.btnOK.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnOK.Location = New System.Drawing.Point(309, 155)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 29
        Me.btnOK.Text = "OK"
        Me.btnOK.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtCommon
        '
        Me.txtCommon.AcceptsReturn = True
        Me.txtCommon.Location = New System.Drawing.Point(15, 99)
        Me.txtCommon.Multiline = True
        Me.txtCommon.Name = "txtCommon"
        Me.txtCommon.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtCommon.Size = New System.Drawing.Size(450, 50)
        Me.txtCommon.TabIndex = 28
        Me.ToolTip1.SetToolTip(Me.txtCommon, "Applicable Common Names (optional)")
        '
        'Label4
        '
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(12, 80)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(216, 16)
        Me.Label4.TabIndex = 27
        Me.Label4.Text = "Applicable Common Names (optional)"
        Me.ToolTip1.SetToolTip(Me.Label4, "Applicable Common Names (optional)")
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(71, 57)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(224, 23)
        Me.Label3.TabIndex = 26
        Me.Label3.Text = "(If rank name = Empire, then value = Biovitae)"
        '
        'txtRValue
        '
        Me.txtRValue.Location = New System.Drawing.Point(135, 31)
        Me.txtRValue.Name = "txtRValue"
        Me.txtRValue.Size = New System.Drawing.Size(160, 20)
        Me.txtRValue.TabIndex = 25
        Me.ToolTip1.SetToolTip(Me.txtRValue, "Taxon Rank Value")
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(12, 34)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(112, 23)
        Me.Label2.TabIndex = 24
        Me.Label2.Text = "Taxon Rank Value"
        Me.ToolTip1.SetToolTip(Me.Label2, "Taxon Rank Value")
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(12, 9)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(120, 16)
        Me.Label1.TabIndex = 22
        Me.Label1.Text = "Taxon Rank Name"
        Me.ToolTip1.SetToolTip(Me.Label1, "Select or type in appropriate rank name")
        '
        'button_example
        '
        Me.button_example.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.button_example.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.button_example.Image = Global.MetaDoc.My.Resources.Resources.app_help_48x48
        Me.button_example.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.button_example.Location = New System.Drawing.Point(354, 12)
        Me.button_example.Name = "button_example"
        Me.button_example.Size = New System.Drawing.Size(110, 48)
        Me.button_example.TabIndex = 32
        Me.button_example.Text = "EXAMPLE"
        Me.button_example.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.button_example.UseVisualStyleBackColor = True
        '
        'frmTaxonClass
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(476, 229)
        Me.ControlBox = False
        Me.Controls.Add(Me.button_example)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.txtCommon)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.txtRValue)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.cboxRName)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmTaxonClass"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Taxonomic Class"
        Me.Panel1.ResumeLayout(False)
        Me.Panel1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub frmTaxonClass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sTemp As String = ""
        Dim iSelIndex As Integer = 0

        If (oTaxRank.RankName <> "") Then 'fill in the taxonomic rank name
            sTemp = oTaxRank.RankName
            iSelIndex = cboxRName.FindStringExact(sTemp)
            If (iSelIndex = -1) Then
                cboxRName.Text = sTemp
            Else
                cboxRName.SelectedIndex = iSelIndex
            End If
        End If

        txtRValue.Text = oTaxRank.RankValue 'fill in the taxonomic rank value -- may be blank
        txtCommon.Text = oTaxRank.CommonName 'fill in the common names -- may be blank

    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Try
            VisitLink()
        Catch ex As Exception
            ' The error message
            MessageBox.Show("Unable to open link that was clicked.")
        End Try
    End Sub

    Sub VisitLink()
        ' Change the color of the link text by setting LinkVisited to True.
        LinkLabel1.LinkVisited = True
        ' Call the Process.Start method to open the default browser 
        ' with a URL:
        System.Diagnostics.Process.Start("http://www.itis.gov")
    End Sub

    Private Sub cboxRName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboxRName.SelectedIndexChanged
        If (cboxRName.SelectedIndex = 0) Then 'if Empire selected as Rank Name, then fill in Rank Value and Common Name
            txtRValue.Text = sEmpireValue
            txtCommon.Text = sEmpireCommon
        End If
        validateOK()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim iSelIndex As Integer = 0
        If (cboxRName.Text = "") Then
            MessageBox.Show("Need to fill in the Rank Name!", "Taxonomic specification error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If
        If (txtRValue.Text = "") Then
            MessageBox.Show("Need to fill in the Rank Value!", "Taxonomic specification error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If
        If (cboxRName.SelectedIndex = 0) Then 'if Empire selected as Rank Name, then fill in Rank Value and Common Name
            txtRValue.Text = sEmpireValue
            txtCommon.Text = sEmpireCommon
        End If
        bUpdate = True
        oTaxRank.RankName = cboxRName.Text
        oTaxRank.RankValue = txtRValue.Text
        oTaxRank.CommonName = txtCommon.Text
        Me.Dispose()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        bUpdate = False
        Me.Dispose()
    End Sub

    Private Sub txtRValue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRValue.TextChanged
        validateOK()
    End Sub

    Private Sub validateOK()
        If cboxRName.SelectedIndex = -1 Or txtRValue.Text.Trim() = "" Then btnOK.Enabled = False Else btnOK.Enabled = True
    End Sub

    Public Function getUpdated() As Boolean
        Return bUpdate
    End Function
    Public Function getTaxRank() As TaxonClass
        Return oTaxRank
    End Function

    Private Sub button_example_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_example.Click
        Dim helpForm As dialog_help = New dialog_help("TaxonClass")
        helpForm.ShowDialog()
    End Sub
End Class
